package com.scuec.tourismwebsite.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scuec.tourismwebsite.entity.FreeformPost;
import com.scuec.tourismwebsite.mapper.FreeformPostMapper;
import com.scuec.tourismwebsite.vo.AdminPost;
import com.scuec.tourismwebsite.vo.UserPost;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class FreeformPostServiceImpl implements FreeformPostService{
    @Autowired
    private FreeformPostMapper freeformPostMapper;

    @Override
    public Integer deleteAPostById(Integer post_id) {
        return freeformPostMapper.deleteAPostById(post_id);
    }

    @Override
    public Integer insertPost(FreeformPost freeformPost) {
        return freeformPostMapper.insertPost(freeformPost);
    }

    @Override
    public AdminPost findAPostById(Integer postId) {
        return freeformPostMapper.findAPostById(postId);
    }

    @Override
    public Integer updateAPostCount(@Param("post_id") Integer post_id, @Param("comments_count") Integer comments_count,@Param("likes_count") Integer likes_count,@Param("collect_counts") Integer collect_counts) {
        return freeformPostMapper.updateAPostCount(post_id, comments_count,likes_count,collect_counts);
    }

    @Override
    public List<AdminPost> findAPostAllByUsername(String username) {
        return freeformPostMapper.findAPostAllByUsername(username);
    }

    @Override
    public List<AdminPost> findAPostAll() {
        return freeformPostMapper.findAPostAll();
    }

    @Override
    public PageInfo<AdminPost> findAdminPostPages(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<AdminPost> lists =freeformPostMapper.findAPostAll() ;
        PageInfo<AdminPost> pageInfo = new PageInfo<>(lists);
        return pageInfo;
    }

    @Override
    public PageInfo<AdminPost> findAdminPostPage(String username, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<AdminPost> lists =freeformPostMapper.findAPostAllByUsername(username) ;
        PageInfo<AdminPost> pageInfo = new PageInfo<>(lists);
        return pageInfo;
    }
}

